﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TelerikAcademyOopProject
{
    public class Buyer : Trader
    {

        /*==========================================*/
        //           Buyer FIELDS
        /*==========================================*/
        private List<Item> buyerList = new List<Item>();
        

        /*==========================================*/
        //           Buyer METHODS
        /*==========================================*/

        public void BuyItem(string itemId)
        {

            //// get current item fro, the list
            var getItem  = this.Manager.ItemDic[itemId];
            
            // checl my Account
            if (AccountCheck(getItem))
            {
                // set it in my stocks
                this.buyerList.Add(getItem);

                // remove it from the list
                this.Manager.RemoveItem(itemId);

                this.TraderAccount.Balance -= (getItem.ItemPrice.PurchasePrice * getItem.ItemCount);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("You dont have enough money, you nead to Deposit your account");
                Console.ResetColor();
            }
        }

        public bool AccountCheck(Item item)
        {
            if (this.TraderAccount.Balance > item.ItemPrice.PurchasePrice)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public void showItemStack()
        {
            if (this.buyerList.Count > 0)
            {
                foreach (var item in this.buyerList)
                {
                    Console.WriteLine(item);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Empty Item Stack");
                Console.ResetColor();
            }

        }

        public override void Deposit(decimal amount)
        {
            this.TraderAccount.Balance = amount;
        }

        

    }
}
